﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<nsadv.Statistic.Web.ViewModels.BannerPeriodicalModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Детализация по баннеру
	"<%: Model.Banner.Name %>"
	<%: Model.Place == null ? "" : string.Format(" ({0})", Model.Place.Name) %>
	<%: Model.Platform == null ? "" : string.Format(" на {0}", Model.Platform.Name) %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
	<h3>
		Детализация по баннеру
		"<%: Model.Banner.Name %>"
		<%: Model.Place == null ? "" : string.Format(" ({0})", Model.Place.Name) %>
		<%: Model.Platform == null ? "" : string.Format(" на {0}", Model.Platform.Name) %>
	</h3>
	<br/>
	<%: Html.ActionLink("Вернуться к списку", "Cabinet") %>
	<br/>
	<br/>
	<table class="banner-details-filter-table">
		<tbody>
			<tr>
				<td valign="top">
					Статистика по дням&nbsp;<input type="radio" checked="checked" onclick="UpdateDetails();"
						title="Статистика по дням" value="Day" name="statPeriod" />
					&nbsp;&nbsp;Статистика по неделям&nbsp;<input type="radio" onclick="UpdateDetails();"
						title="Статистика по неделям" value="Week" name="statPeriod" />
					&nbsp;&nbsp;Статистика по месяцам&nbsp;<input type="radio" onclick="UpdateDetails();"
						title="Статистика по месяцам" value="Month" name="statPeriod" />
				</td>
			</tr>
			<tr>
				<td>
					<table width="100%">
						<tbody>
							<tr>
								<td align="left">
									Выберите даты:
								</td>
								<td align="right">
									C
								</td>
								<td align="left">
									<input type="text" id="datepickerFrom" size="14">
								</td>
								<td align="right">
									По
								</td>
								<td align="left">
									<input type="text" id="datepickerTo" size="14">
								</td>
								<td align="right">
									<input type="button" onclick="javascript:UpdateDetails();" value="Вывести">
								</td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
		</tbody>
	</table>
	<div id="bannerdetails">
	</div>
	<script type="text/javascript">

		$(function () {

			$.datepicker.setDefaults($.datepicker.regional['ru']);

			$("#datepickerFrom").datepicker({
				showOn: 'button',
				buttonImage: '/Content/images/calendar.gif',
				buttonImageOnly: true,
				changeYear: true,
				changeMonth: true
			});

			$("#datepickerTo").datepicker({
				showOn: 'button',
				buttonImage: '/Content/images/calendar.gif',
				buttonImageOnly: true,
				changeYear: true,
				changeMonth: true
			});

			$.datepicker.setDefaults($.datepicker.regional['ru']);

			$("#datepickerFrom").datepicker("setDate", "-1m");
			$("#datepickerTo").datepicker("setDate", "+0");

			UpdateDetails();

		});

        function handleFailure(ajaxContext) {
            $("#bannerdetails").html('<div class="stat-loader-text">Ошибка...</div><p>' + ajaxContext.get_data() +'</p>');
        }

        function handleSuccess(ajaxContext) {
            $('.tooltip').tooltip({bgcolor: '#ede5b8', bordercolor: '#bf9552', fontcolor: '#000000'});		
        }

		function GetPeriod() {
			var vrdTperiod = $("#statPeriod");
			if (vrdTperiod != null && vrdTperiod != 'undefined') {
				Period =$('input[name=statPeriod]:checked').val();
				if (Period == 'undefined') {
					Period = 'Day';
				}
			}
			else {
				Period = 'Day';
			}
		} 

        function UpdateDetails() {
        	$("#bannerdetails").html('<div class="stat-loader-text">Загрузка статистики <span id="stat-loader-text-times"></span>...</div><img class="stat-loader" src="/Content/img/ajax-loader.gif" alt="loader" />');

			GetPeriod();

            Sys.Mvc.MvcHelpers._asyncRequest(
            '<%: Url.Action("BannerPeriodicalDetails", "Statistic", null) %>',
            'post',
               'BannerId=' + '<%: Model.Banner.Id %>'
			+ '&PlatformId=' + '<%: Model.Platform == null ? "" : Model.Platform.Id %>'
			+ '&PlaceId=' + '<%: Model.Place == null ? "" : Model.Place.Id %>'
			+ '&Groupping=' + Period
			+ '&From=' + $("#datepickerFrom")[0].value //$("#datepickerFrom").datepicker("getDate")
			+ '&To=' + $("#datepickerTo")[0].value, //$("#datepickerTo").datepicker("getDate"),
            '',
            { insertionMode: Sys.Mvc.InsertionMode.replace,
              updateTargetId: 'bannerdetails',
              onSuccess: Function.createDelegate(this, handleSuccess), 
              onFailure: Function.createDelegate(this, handleFailure),
              LoadingElementId: 'stat-loader-text-times'
             });
            }

	</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="DocumentReadyScript" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Head" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Footer" runat="server">
</asp:Content>
